import React from 'react';
import {Form} from "antd";
import {Tooltip, Icon} from 'antd';

export const TooltipLabel = ({label, title}) => (
  <span>
    {label}&nbsp;
    <Tooltip placement="top" title={title}>
      <Icon type="question-circle"/>
    </Tooltip>
  </span>
);
export default {
  formItemLayout: {
    labelCol: {span: 6},
    wrapperCol: {span: 14},
  },
  noLabelItemCol: 6,
  createOption: {
    onFieldsChange(props, changedFields) {
      if (props.onChange) {
        props.onChange(changedFields);
      }
    },
    mapPropsToFields(props) {
      if (props) {
        const map = {};
        Object.keys(props).map((field) => {
          map[field] = Form.createFormField({
            ...props[field],
            value: props[field].value,
          });
          return field;
        });
        return map;
      }
    },
  },
  customControl: prop => ({
    isSingle: 'true',
    isHideTitle: 'true',
    titleLayout: 'title-vert',
    ...prop,
  }),
  single2array: item => item ? [item] : [],
  array2single: items => (items && Array.isArray(items) && items.length > 0) ? items[0] : null,
  TooltipLabel,
};

